<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>头部导航</title>
    <script src="../js/jquery-3.3.1.min.js"></script>
    <style>
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        .nav{
            list-style: none;
            overflow: hidden;
            margin: 0 auto;
        }

        .nav>li {
            float: left;
            width: 100px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            border: 1px solid lightblue;
            cursor: pointer;
        }
        .nav>li.on{
            background: cornflowerblue;
            color: white;
        }
        .page{
            width: 500px;
            line-height: 500px;
            background: #f5f5f5;
            display: none;
            text-align: center;
        }

        .nav2{
            width: 200px;
            text-align: center;
        }

        .nav2>li{

        }
        .nav2>li>span{
            padding: 20px 30px;
            cursor: pointer;
            display: inline-block;
            border-bottom: 1px solid #222222;
        }
        .nav2 ul{
            display: none;
        }

        .ani{
            width: 500px;
            height: 500px;
            background: #222222;
        }

    </style>
</head>

<body>
<ul class="nav">
    <li data-id="index" class="on">首页</li>
    <li data-id="news">新闻中心</li>
    <li data-id="company">企业动态</li>
    <li data-id="out">联系我们</li>
</ul>

<div class="page" id="index">首页</div>
<div class="page" id="news">新闻中心</div>
<div class="page" id="company">企业动态</div>
<div class="page" id="out">联系我们</div>

<ul class="nav2">
    <li>
        <span>苹果</span>
        <ul>
            <li>红苹果</li>
            <li>青苹果</li>
            <li>小苹果</li>
        </ul>
    </li>
    <li>
        <span>橘子</span>
        <ul>
            <li>红橘子</li>
            <li>青橘子</li>
        </ul>
    </li>
    <li>
        <span>西瓜</span>
        <ul>
            <li>红西瓜</li>
            <li>小西瓜</li>
        </ul>
    </li>
</ul>

<button type="button">
    点击查看动画
</button>
<div class="ani"></div>


<script>

    $('#index').show();
    $('.nav>li:first').addClass('on');

    $('.nav>li').click(function () {

        $(this).addClass('on');

        $(this).siblings().removeClass('on');

        var dataId = $(this).data('id');
        $('.page').hide();
//        $('#'+dataId).show(500);
        $('#'+dataId).fadeIn(500);

    });


    $('span').click(function(){

        $('.nav2 ul').slideUp();

        $(this).next('ul').slideDown();

    });

    $('button').click(function(){

        $('.ani').animate({
            width:'200px',
            height:'200px'
        },1000,function(){
            alert('动画结束');
        });

    });


</script>
</body>
</html>